package org.brownflat.lighthouse.monitoring.ci.hudson;

import org.apache.log4j.Logger;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * &copy; Rupert Jones 2011
 */
public class PatternBrokenBuildDecisionMaker implements BrokenBuildDecisionMaker {
    private static final Logger LOG = Logger.getLogger(PatternBrokenBuildDecisionMaker.class);
    private Pattern pattern;

    public PatternBrokenBuildDecisionMaker(String pattern) {
        this.pattern = Pattern.compile(pattern);
    }

    @Override
    public boolean broken(String rssContent) {
        Matcher matcher = pattern.matcher(rssContent);
        boolean result = matcher.matches();
        LOG.debug(String.format("Result of pattern match with content [pattern: %s][result: %s]", pattern.pattern(), result));
        return matcher.matches();
    }
}
